#ifndef __PAGELIBPREPROCESSOR_H__
#define __PAGELIBPREPROCESSOR_H__

#include "./simhash/Simhasher.hpp"
#include <string>
#include <vector>

using namespace simhash;

using std::string;
using std::vector;
using std::unordered_map;

const char * const DICT_PATH1 = "../include/simhash/dict/jieba.dict.utf8";//最大概率法(MPSegment: Max Probability)分词所使用的词典路径
const char * const HMM_PATH1 = "../include/simhash/dict/hmm_model.utf8";//隐式马尔科夫模型(HMMSegment: Hidden Markov Model)分词所使用的词典路径
const char * const USER_DICT_PATH1 = "../include/simhash/dict/user.dict.utf8";//用户自定义词典路径
const char* const IDF_PATH1= "../include/simhash/dict/idf.utf8";//IDF路径
const char* const STOP_WORD_PATH1 = "../include/simhash/dict/stop_words.utf8";//停用词路径

class PageLibPreprocessor
{
    class AutoRelease {
    public:
        AutoRelease() {
            // std::cout << "AutoRelease()" << std::endl;
        }

        ~AutoRelease() {
            // std::cout << "~AutoRelease()" << std::endl;
            if (_pInstance)
                delete _pInstance;
        }
    };

public:
    static PageLibPreprocessor* getInstance() {
        if (_pInstance == nullptr) {
            _pInstance = new PageLibPreprocessor();
        }
        return _pInstance;
    }


    bool isSame(const uint64_t &lhs, const uint64_t &rhs, unsigned short threshold);
    
    void getSimHasher(const string &str, size_t topN, uint64_t &u64);



private:
    PageLibPreprocessor()
    : _simhasher(DICT_PATH1, HMM_PATH1, IDF_PATH1, STOP_WORD_PATH1)
    {}

    PageLibPreprocessor(const PageLibPreprocessor&) = delete;
    PageLibPreprocessor& operator=(const PageLibPreprocessor&) = delete; 
private:
    static AutoRelease _ar;
    static PageLibPreprocessor* _pInstance;
    Simhasher _simhasher;
};


#endif